//
//  YHFileManager.cpp
//  ThunderWarriors
//
//  Created by mac on 13-3-2.
//
//

#include "YHFileManager.h"
#include "stdio.h"


YHFileManger* YHFileManger::m_Instance = NULL;

YHFileManger* YHFileManger::sharedInstance()
{
    if (NULL == m_Instance) {
        m_Instance = new YHFileManger();
        if (m_Instance) {
            bool ret = m_Instance->init();
            if (!ret) {
                delete m_Instance;
                m_Instance = NULL;
            }
        }
    }
    return m_Instance;
}

void YHFileManger::destroyInstance()
{
    if (m_Instance) {
        m_Instance->uninit();
    }
    delete m_Instance;
    m_Instance = NULL;
}

bool YHFileManger::init()
{
    setResourceDirectory(fullPathFromRelativeFile("", ""));
    
    createDirectory("Hi/",getWriteablePath() );
    return true;
}

void YHFileManger::uninit()
{
    
}

YHFileManger::YHFileManger()
{
    
}

YHFileManger::~YHFileManger()
{
    
}

void YHFileManger::setResourceDirectory(const char *pszDirectoryName)
{
    CCFileUtils::sharedFileUtils()->setResourceDirectory(pszDirectoryName);
}

const char* YHFileManger::getResourceDirectory()
{
    std::string resourcePath = CCFileUtils::sharedFileUtils()->getResourceDirectory();
    return resourcePath.c_str();
}

const char* YHFileManger::getWriteablePath()
{
    std::string writePath = CCFileUtils::sharedFileUtils()->getWriteablePath();
    return writePath.c_str();
}

const char* YHFileManger::fullPathFromRelativePath(const char *pszRelativePath)
{
    if (0 == strcmp(pszRelativePath, "")) {
        return fullPathFromRelativeFile("", "");
    }
    std::string path = CCFileUtils::sharedFileUtils()->fullPathFromRelativePath(pszRelativePath);
    return path.c_str();
}

const char* YHFileManger::fullPathFromRelativeFile(const char *pszFilename, const char *pszRelativeFile)
{
    std::string path2 = CCFileUtils::sharedFileUtils()->fullPathFromRelativeFile(pszFilename, pszRelativeFile);
    return path2.c_str();
}

unsigned char* YHFileManger::getFileData(const char* pszFileName, const char* pszMode, unsigned long * pSize)
{
    return CCFileUtils::sharedFileUtils()->getFileData(pszFileName, pszMode, pSize);
}

unsigned char* YHFileManger::getFileDataFromZip(const char* pszZipFilePath, const char* pszFileName, unsigned long * pSize)
{
    return CCFileUtils::sharedFileUtils()->getFileDataFromZip(pszZipFilePath, pszFileName, pSize);
}

//创建文件夹，能够递归建立
void YHFileManger::createDirectory(const char* newDirectory, const char* atPath)
{
    /*
    std::string fullPath = atPath;
    fullPath.append(newDirectory);
    CCLog("%s", fullPath.c_str());
    fopen(fullPath.c_str(), "wb");*/
}

//删除文件夹
void YHFileManger::removeDirectory(const char* fullPathDirectory)
{
    
}

//删除文件夹，atPath是主目录，relativeDirectory是相对目录
void YHFileManger::removeDirectory(const char* relativeDirectory, const char* atPath)
{
    
}
